﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Recon.Portal.Business;
using Recon.Portal.DataObjects;

namespace Recon.Portal.WebUI
{
    public partial class ReconSignIn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label lblDateTime = ((Label)Master.FindControl("lblDateTime"));
            lblDateTime.Visible = false;
            HyperLink link = ((HyperLink)Master.FindControl("hyprChangePwd"));
            link.Visible = false;
            
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            //set focus on the Customer ID text box
            ((TextBox)SignInControl.FindControl("txtCustID")).Focus();
        }

        protected void SignInControl_Authenticate(object sender, AuthenticateEventArgs e)
        {
            UserEntity uEntity = new UserEntity();
            User user = new Recon.Portal.DataObjects.User
            {
                UserID= SignInControl.UserName,
                Password= SignInControl.Password,
                CustomerID= ((TextBox)SignInControl.FindControl("txtCustID")).Text
            };
            e.Authenticated = uEntity.ValidateUser(user);
            if (!e.Authenticated)
            {
                ((Label)SignInControl.FindControl("lblValidationFailure")).Visible = true;
            }
        }

        protected void SignInControl_LoggedIn(object sender, EventArgs e)
        {
            User loggedUser = (User)HttpContext.Current.Session["CurrentUserVO"];
            if (loggedUser != null)
            {
                Response.Redirect((loggedUser.IsForcedPasswordChange) ? "ChangePassword.aspx" : "ReconHome.aspx");
            }
        }
    }
}